<template>
  <HomePanel title="人气推荐" sub-title="人气爆款 不容错过" ref="target">
      <template #mian>
        <ul class="goods-list">
            <li v-for="item in list" :key="item.id">
                <RouterLink to="/">
                <img alt="" v-imgLazy="item.picture" />
                <p class="name">{{item.title}}</p>
                <p class="desc">{{item.alt}}</p>
                </RouterLink>
            </li>
        </ul>
      </template>

  </HomePanel>
</template>

<script>
import HomePanel from './home-panel'
import { findHot } from '@/api/home'
import { ref } from 'vue'
// 引入组件懒加载逻辑
import { useObserver } from '@/compositions'
export default {
  name: 'HomeHot',
  components: { HomePanel },
  setup () {
    // 1.定义响应式数据
    const list = ref([])
    // 封装获取数据方法
    async function load () {
      const res = await findHot()
      //   console.log(res)
      list.value = res.result
    }
    // 页面一打开就调用获取数据方法获取数据
    // onMounted(() => {
    //   load()
    // })

    // 组件懒加载
    const { target } = useObserver(load)
    return {
      list,
      target
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
